<?php

namespace Xu;

/**
 * Created by PhpStorm.
 * User: xw
 * Date: 2018/3/5
 * Time: 15:56
 */

trait ReturnJson
{

    /**
     * 返回json
     */
    public function returnJson($status, $arr = '', $result = '')
    {
        return response()->json($this->returnData($status, $arr, $result));
    }

    /**
     * 返回array
     */
    public function returnInfo($status, $arr = '', $result = '')
    {
        return $this->returnData($status, $arr, $result);
    }

    private function returnData($status, $arr, $result)
    {
        if($status){
            $data = ['status_code' => 200, 'status' => $status, 'message' => $arr, 'data' => $result];
        }else{
            $data = ['status_code' => 200, 'status' => 0, 'message' => 'success', 'data' => $arr];
        }
        return $data;
    }

}